﻿namespace OboutInc.ImageZoom.ImageFactory
{
    using System;
    using System.Drawing;
    using System.Runtime.CompilerServices;

    internal class ImageZoomWaterMark
    {
        private Bitmap _bmp;
        private Brush _brush;
        private Color _color;
        private Font _font;
        private string _text;

        public ImageZoomWaterMark()
        {
            this._color = Color.FromArgb(0x7f, Color.WhiteSmoke);
            this._font = new Font("verdana", 14f, FontStyle.Bold);
            this._brush = new SolidBrush(this._color);
        }

        public ImageZoomWaterMark(Bitmap _image, string text)
        {
            this.Image = _image;
            this._color = Color.FromArgb(0x7f, Color.WhiteSmoke);
            this._font = new Font("verdana", 14f, FontStyle.Bold);
            this._brush = new SolidBrush(this._color);
            this._text = text;
        }

        internal void AddWatermark()
        {
            int num;
            Graphics graphics;
            string str2 = "1";
            if (str2 != null)
            {
                if (!(str2 == "100%"))
                {
                    if (str2 == "75%")
                    {
                        num = 0xbf;
                        goto Label_0076;
                    }
                    if (str2 == "50%")
                    {
                        num = 0x7f;
                        goto Label_0076;
                    }
                    if (str2 == "25%")
                    {
                        num = 0x40;
                        goto Label_0076;
                    }
                    if (str2 == "10%")
                    {
                        num = 0x19;
                        goto Label_0076;
                    }
                }
                else
                {
                    num = 0xff;
                    goto Label_0076;
                }
            }
            num = 0x7f;
        Label_0076:
            if (num == 0xe1)
            {
                num = 1;
            }
            try
            {
                graphics = Graphics.FromImage(this.Image);
            }
            catch (Exception exception1)
            {
                if (exception1 != null)
                {
                }
                throw;
            }
            Bitmap image = new Bitmap(this.Image.Width, this.Image.Height);
            graphics = Graphics.FromImage(image);
            graphics.DrawImage(this.Image, new Rectangle(0, 0, this.Image.Width, this.Image.Height), 0, 0, this.Image.Width, this.Image.Height, GraphicsUnit.Pixel);
            this.Image = image;
            int width = this.Image.Width;
            int height = this.Image.Height;
            SizeF ef = graphics.MeasureString(this._text, this._font);
            int num4 = (width - ((int) ef.Width)) / 2;
            if (num4 < 0)
            {
                num4 = 0;
            }
            int num5 = (height - ((int) ef.Height)) / 2;
            if (num5 < 0)
            {
                num5 = 0;
            }
            graphics.DrawString(this._text, this._font, this._brush, (float) num4, (float) num5);
        }

        internal void AddWaterMark(Graphics canvas, string text, Rectangle rect)
        {
            canvas.DrawString(text, this._font, this._brush, rect);
        }

        internal void AddWaterMark(Graphics canvas, string text, int width, int height)
        {
            SizeF ef = canvas.MeasureString(text, this._font);
            int num = (width - ((int) ef.Width)) / 2;
            if (num < 0)
            {
                num = 0;
            }
            int num2 = (height - ((int) ef.Height)) / 2;
            if (num2 < 0)
            {
                num2 = 0;
            }
            canvas.DrawString(text, this._font, this._brush, (float) num, (float) num2);
        }

        internal void AddWaterMark(Graphics canvas, string text, Rectangle rect, Color color, string fontFamily, int fontSize, FontStyle fontStyle)
        {
            Font font = new Font(fontFamily, (float) fontSize, fontStyle);
            Brush brush = new SolidBrush(Color.FromArgb(0x7f, color));
            canvas.DrawString(text, font, brush, rect);
        }

        public Graphics Canvas { get; set; }

        public Bitmap Image
        {
            get
            {
                return this._bmp;
            }
            set
            {
                this._bmp = value;
            }
        }
    }
}

